<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="~/assets/logo.png" alt="" style="height:50px;width:50px" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主题区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 放在keep-alive中的组件必须带结束符号,不能成对出现 -->
        <keep-alive>
          <home-menu :isCollapse="isCollapse" />
        </keep-alive>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import HomeMenu from "./childComponents/HomeMenu";
export default {
  name: "Home",
  data() {
    return {
      isCollapse: false
    };
  },
  components: {
    HomeMenu
  },

  methods: {
    //登出
    logout() {
      //清空全部sessionStorage
      window.sessionStorage.clear();
      // window.sessionStorage.setItem("token", null);
      this.$message.success({ showClose: true, message: "退出成功" });
      this.$router.push("/login");
    },
    //点击按钮,控制侧边栏折叠展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    }
  }
};
</script>

<style lang="less" scoped>
.home-container {
  //   height: 100%;
  height: 100vh;
  overflow-y: hidden;
}
.el-header {
  background-color: #373d41;
  // 弹性布局
  display: flex;
  // 弹性布局,定义了项目在主轴上的对齐方式,两端对齐，项目之间的间隔都相等
  justify-content: space-between;
  padding-left: 0px;
  // 弹性布局,使按钮上下居中
  align-items: center;
  color: #ffff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  transition: all 0.8s ease;
}
.el-main {
  background-color: #eaedf1;
  height: calc(100vh - 60px);
  overflow-y: auto;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px; //行高
  color: #fff;
  text-align: center; //上下居中
  letter-spacing: 0.2em; //字间距
  cursor: pointer;
}
</style>
